package com.gongj.shej.demo;

/**
 * @program: shej
 * @description:简单工厂模式
 * @author: gongj
 * @Description: TODO
 * @create: 2020-07-22 14:03
 **/
public class SimpleFoodFactory {

    public static IProduct createProduct(String name) {
        IProduct product = null;
        switch (name) {
            case "pizza":
                product = new Pizza();
                break;
            case "hamburger":
                product = new Hamburger();
                break;
        }
        return product;
    }

    public static void main(String[] args) {
        SimpleFoodFactory.createProduct("hamburger").makeFood();
    }
}


/**
 * @program: shej
 * @description:抽象产品类
 * @author: gongj
 * @Description: TODO
 * @create: 2020-07-22 14:14
 **/
abstract class IProduct {
    /**
     * 产品的抽象方法，由具体的产品类去实现
     */
    public abstract void makeFood();
}

/**
 * @program: shej
 * @description: 具体产品-披萨
 * @author: gongj
 * @Description: TODO
 * @create: 2020-07-22 14:15
 **/
class Pizza extends IProduct{
    @Override
    public void makeFood() {
        System.out.println("制作具体产品-披萨");
    }
}


/**
 * @program: shej
 * @description: 具体产品-汉堡
 * @author: gongj
 * @Description: TODO
 * @create: 2020-07-22 14:16
 **/
class Hamburger extends IProduct {
    @Override
    public void makeFood() {
        System.out.println("制作具体产品-汉堡");
    }
}